package cn.fl.ass.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.condition.SysUsrQueryCondition;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.ass.service.IAssParkingMgService;
import cn.fl.ass.service.IAssParkingService;
import cn.fl.ass.service.IAssParkingValidService;
import cn.fl.ass.vo.AssParkingMgVO;
import cn.fl.ass.vo.AssParkingVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;

import com.alibaba.fastjson.JSONObject;

import fl.ass.facade.condition.AssParkingMgQueryCondition;
import fl.ass.facade.condition.AssParkingQueryCondition;
import fl.ass.facade.condition.AssParkingValidQueryCondition;
import fl.ass.facade.constant.AssFileConstant;
import fl.ass.facade.dto.AssParkingMgDTO;
import fl.ass.facade.dto.AssParkingValidDTO;

/**
 * @Description: 停车场表 控制层
 */
@Controller
@RequestMapping("/ass/assParking")
public class AssParkingController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AssParkingController.class);

	/**
	 * AssParking 停车场服务层BEAN
	 */
	@Autowired
	private IAssParkingService assParkingService;
	
	/**
	 * AssParkingMg 资产管理员服务层BEAN
	 */
	@Autowired
	private IAssParkingMgService assParkingMgService;
	
	/**
	 * AssParkingValid 停车场有效期服务层BEAN
	 */
	@Autowired
	private IAssParkingValidService assParkingValidService;
	
	/**
	 * 附件服务
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;
	
	@Autowired
	private ISysUsrApiService sysUsrApiService;//系统用户API 暴露服务

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("ass/assParking/assParkingInfoList");
		return view;
	}
	
	/**
	 * 到新增页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String validId = request.getParameter("validId");
		ModelAndView view = new ModelAndView("ass/assParking/assParkingInfoAdd");
		view.addObject("id", id);
		view.addObject("validId", validId);
		//获取资产管理员信息
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingMgQueryCondition qc = new AssParkingMgQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingMgDTO> assMgsList = this.assParkingMgService.searchAssMgsList(qc);
			view.addObject("assMgsList", assMgsList);
		}
		view.addObject("sysDate", DateUtils.formatDateToString(new Date(), DateUtils.YYYY_MM_DD));
		view.addObject("loginUsrNm", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String validId = request.getParameter("validId");
		ModelAndView view = new ModelAndView("ass/assParking/assParkingInfoModify");
		view.addObject("id", id);
		view.addObject("validId", validId);
		//获取资产管理员信息
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingMgQueryCondition qc = new AssParkingMgQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingMgDTO> assMgsList = this.assParkingMgService.searchAssMgsList(qc);
			view.addObject("assMgsList", assMgsList);
		}
		//获取历史有效期主键List
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingValidQueryCondition qc = new AssParkingValidQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingValidDTO> validList = this.assParkingValidService.searchValidList(qc);
			if(null != validList){
				List<Long> validIdList = new ArrayList<Long>();
				for (AssParkingValidDTO dto : validList) {
					if(dto.getIsNew()==0){
						validIdList.add(dto.getId());
					}
				}
				view.addObject("validIdList", validIdList);
			}
		}
		view.addObject("sysDate", DateUtils.formatDateToString(new Date(), DateUtils.YYYY_MM_DD));
		view.addObject("loginUsrNm", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 跳转到停车场详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String validId = request.getParameter("validId");
		String provinceCity = request.getParameter("provinceCity");
		ModelAndView view = new ModelAndView("ass/assParking/assParkingInfoDetail");
		view.addObject("id", id);
		view.addObject("validId", validId);
		view.addObject("provinceCity", provinceCity);
		//获取资产管理员信息
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingMgQueryCondition qc = new AssParkingMgQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingMgDTO> assMgsList = this.assParkingMgService.searchAssMgsList(qc);
			view.addObject("assMgsList", assMgsList);
		}
		//获取历史有效期主键List
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingValidQueryCondition qc = new AssParkingValidQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingValidDTO> validList = this.assParkingValidService.searchValidList(qc);
			if(null != validList){
				List<Long> validIdList = new ArrayList<Long>();
				for (AssParkingValidDTO dto : validList) {
					if(dto.getIsNew()==0){
						validIdList.add(dto.getId());
					}
				}
				view.addObject("validIdList", validIdList);
			}
		}
		return view;
	}
	
	/**
	 * 跳转到停车场合同续签页面
	 */
	@RequestMapping(value = "/toRenewPage.do", method = { RequestMethod.GET})
	public ModelAndView toRenewPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String validId = request.getParameter("validId");
		String provinceCity = request.getParameter("provinceCity");
		ModelAndView view = new ModelAndView("ass/assParking/assParkingRenew");
		view.addObject("id", id);
		view.addObject("validId", validId);
		view.addObject("provinceCity", provinceCity);
		//获取资产管理员信息
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingMgQueryCondition qc = new AssParkingMgQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingMgDTO> assMgsList = this.assParkingMgService.searchAssMgsList(qc);
			view.addObject("assMgsList", assMgsList);
		}
		//获取历史有效期主键List
		if(StringUtils.isNotEmpty(id)){
			Long pardId = Long.parseLong(id);
			AssParkingValidQueryCondition qc = new AssParkingValidQueryCondition();
			qc.setParkId(pardId);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			List<AssParkingValidDTO> validList = this.assParkingValidService.searchValidList(qc);
			if(null != validList){
				List<Long> validIdList = new ArrayList<Long>();
				for (AssParkingValidDTO dto : validList) {
					if(dto.getIsNew()==0){
						validIdList.add(dto.getId());
					}
				}
				view.addObject("validIdList", validIdList);
			}
		}
		view.addObject("sysDate", DateUtils.formatDateToString(new Date(), DateUtils.YYYY_MM_DD));
		view.addObject("loginUsrNm", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		// 查询条件
		String parkCd = request.getParameter("parkCd");
		String parkNm = request.getParameter("parkNm");
		String assManagers = request.getParameter("assManagers");
		String vFlag = request.getParameter("vFlag");
		String parkStatus = request.getParameter("parkStatus");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		// 停车场表统一查询条件
		AssParkingQueryCondition qc = new AssParkingQueryCondition();
		if (StringUtils.isNotEmpty(parkCd)) {
			qc.setParkCd(parkCd.toUpperCase());//小写转大写
		}
		if (StringUtils.isNotEmpty(parkNm)) {
			qc.setParkNm(parkNm);
		}
		if (StringUtils.isNotEmpty(assManagers)) {
			//qc.setAssManagers(assManagers);
			//1.根据“资管员-名称”模糊查询符合条件的人员ID(mgIdList)
			List<Long> mgIdList = new ArrayList<Long>();
			SysUsrQueryCondition usQc = new SysUsrQueryCondition();
			usQc.setSysCd("11000");
			usQc.setRlNm(assManagers);
			List<SysUsrDTO> usrList = this.sysUsrApiService.searchSysUsrList(usQc);
			if(CollectionUtils.isNotEmpty(usrList) && usrList.size()>0){
				for(SysUsrDTO usr : usrList){
					mgIdList.add(usr.getId());
				}
				//2.根据mgIdList在资管表里查询对应的停车场parkIdList
				List<String> parkIdList = new ArrayList<String>();
				AssParkingMgQueryCondition mgQc = new AssParkingMgQueryCondition();
				mgQc.setMgIdList(mgIdList);
				List<AssParkingMgDTO> mgList = this.assParkingMgService.searchAssMgsList(mgQc);
				if(CollectionUtils.isNotEmpty(mgList) && mgList.size()>0){
					for(AssParkingMgDTO mg : mgList){
						parkIdList.add(mg.getParkId().toString());
					}
					//3.将结果parkIdList放入停车场查询条件
					qc.setParkIdsList(parkIdList);
				}else{
					qc.setId(0L);//目的：置空结果集
				}
			}else{
				qc.setId(0L);//目的：置空结果集
			}
		}
		if (StringUtils.isNotEmpty(vFlag)) {
			qc.setvFlag(Integer.parseInt(vFlag));
		}
		if (StringUtils.isNotEmpty(parkStatus)) {
			qc.setParkStatus(Integer.parseInt(parkStatus));
		}
		page.setCondition(qc);
		// 查询停车场相关信息
		Pager pager = this.assParkingService.searchListPage(page);
		List<AssParkingVO> list = (List<AssParkingVO>) pager.getResultList();
		ListPageVO<AssParkingVO> listPage = new ListPageVO<AssParkingVO>(list, pager.getTotalCount());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.assParkingService.removeById(Long.valueOf(id));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		
		try {
			AssParkingVO vo = this.assParkingService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newLogger("AssParkingController getById 获取失败 BaseException").setBussinessId(id).setThrowable(ex).info();
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("AssParkingController getById 获取失败 Exception").setBussinessId(id).setThrowable(ex).info();
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		// 获取页面参数
		String parkNm = request.getParameter("parkNm");
		String provinceCd = request.getParameter("provinceCd");
		String cityCd = request.getParameter("cityCd");
		String contactNm = request.getParameter("contactNm");
		String contactTel = request.getParameter("contactTel");
		String parkAddress = request.getParameter("parkAddress");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		AssParkingVO entity = null;
		try {
			entity = new AssParkingVO();
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setCrtTm(new Date());
			entity.setIsDel(BaseConstant.IS_YESNO_NO);
			// 设置页面参数
			entity.setParkNm(parkNm);
			entity.setProvinceCd(provinceCd);
			entity.setCityCd(cityCd);
			entity.setContactNm(contactNm);
			entity.setContactTel(contactTel);
			entity.setParkAddress(parkAddress);
			Long parkId = this.assParkingService.add(entity);
			result.setData(parkId);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newLogger("新增停车场数据失败 BaseException").setKeys("entity:" + JSONObject.toJSONString(entity)).setThrowable(ex).info();
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("新增停车场数据失败 Exception").setKeys("entity:" + JSONObject.toJSONString(entity)).setThrowable(ex).info();
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		// 获取页面参数
		String parkNm = request.getParameter("parkNm");
		String provinceCd = request.getParameter("provinceCd");
		String cityCd = request.getParameter("cityCd");
		String contactNm = request.getParameter("contactNm");
		String contactTel = request.getParameter("contactTel");
		String parkAddress = request.getParameter("parkAddress");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		AssParkingVO entity = null;
		try {
			entity = new AssParkingVO();
			entity.setId(Long.valueOf(id));
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setMdfTm(new Date());
			// 设置页面参数
			entity.setParkNm(parkNm);
			entity.setProvinceCd(provinceCd);
			entity.setCityCd(cityCd);
			entity.setContactNm(contactNm);
			entity.setContactTel(contactTel);
			entity.setParkAddress(parkAddress);
			boolean success = this.assParkingService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("修改停车场数据失败 BaseException").setBussinessId(id).setKeys("entity:" + JSONObject.toJSONString(entity)).setThrowable(ex).info();
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("修改停车场数据失败 BaseException").setBussinessId(id).setKeys("entity:" + JSONObject.toJSONString(entity)).setThrowable(ex).info();
		}
		return result;
	}
	
	/**
	 * 保存附件信息
	 */
	@RequestMapping(value = "/uploadAttchment.do", method = { RequestMethod.POST,RequestMethod.GET })
	@ResponseBody
	public Object uploadAttchment(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String attchmnt = request.getParameter("docArray");
		String id = request.getParameter("validId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_FILE_UPLOAD_SUCC);
		if(StringUtils.isNotEmpty(attchmnt)){
			//上传解析
			try{
				String cfgCd = AssFileConstant.ASS_PARKING_CFGCD;
				String cfgDtlCd = AssFileConstant.ASS_PARKING_CFGDTLCD_10;
				String tabNm = AssFileConstant.ASS_PARKING_TABNM;
				String cfgOrgCd = AssFileConstant.ASS_PARKING_CFGORG;
				Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(String.valueOf(id), attchmnt, cfgCd, cfgDtlCd, tabNm, "停车场信息附件!", null, null, false, cfgOrgCd);
				if(null == attchmntPass || attchmntPass == false){
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("停车场附件上传失败!");
				}
				result.setData(id);//设置附件关联主键
			}catch (BaseException ex) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(ex.getMessage());
				BaseLogUtils.newLogger("停车场附件上传失败 BaseException").setBussinessId(id).setThrowable(ex).info();
			}catch (Exception ex) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
                BaseLogUtils.newLogger("停车场附件上传失败 Exception").setBussinessId(id).setThrowable(ex).info();
			}
		}
		return result;
	}
	
	/**
	 * 导出停车场信息
	 */
	@RequestMapping(value = "/exportAssParking.do", method = { RequestMethod.POST,RequestMethod.GET })
	@ResponseBody
	public Object exportAssParking(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_BK_EXPORT_SUCC);
		String parkCd = request.getParameter("parkCd");
		String parkNm = request.getParameter("parkNm");
		String assManagers = request.getParameter("assManagers");
		String vFlag = request.getParameter("vFlag");
		String parkStatus = request.getParameter("parkStatus");
		String parkIds = request.getParameter("parkIds");//停车场IDList
		
		try {
			// 停车场表统一查询条件
			AssParkingQueryCondition qc = new AssParkingQueryCondition();
			if (StringUtils.isNotEmpty(parkCd)) {
				qc.setParkCd(parkCd);
			}
			if (StringUtils.isNotEmpty(parkNm)) {
				qc.setParkNm(parkNm);
			}
			if (StringUtils.isNotEmpty(assManagers)) {
				qc.setAssManagers(assManagers);
			}
			if (StringUtils.isNotEmpty(vFlag)) {
				qc.setvFlag(Integer.parseInt(vFlag));
			}
			if (StringUtils.isNotEmpty(parkStatus)) {
				qc.setParkStatus(Integer.parseInt(parkStatus));
			}
			//要导出的停车场ID列表
			if(StringUtils.isNotEmpty(parkIds)){
				List<String> parkIdsList = new ArrayList<String>();
				JSONArray parkIdsArray = JSONArray.fromObject(parkIds);
				for (Object object : parkIdsArray) {
					parkIdsList.add(object.toString());
				}
				qc.setParkIdsList(parkIdsList);
			}
			String path = this.assParkingService.exportAssParking(qc, CurrentThreadContext.getCurrentOrgCd());
			if(StringUtils.isNotEmpty(path)){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo(SysLogConstant.LOG_BK_EXPORT_SUCC);
				result.setData(path);
			}
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newLogger("导出停车场数据失败 BaseException").setThrowable(ex).info();
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("导出停车场数据失败 Exception").setThrowable(ex).info();
		}
		
		return result;
	}
	
	/**
	 * 根据城市代码获取停车场名称数据
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getParkNmByRgnCd.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getParkNmByRgnCd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String provinceCd = request.getParameter("provinceCd");
		String cityCd = request.getParameter("cityCd");
		String parkId = request.getParameter("parkId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isBlank(provinceCd) || StringUtils.isBlank(cityCd)){
		    result.setSuccess(BaseConstant.IS_YESNO_NO);
		    result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
		    return result;
		}
		try {
			
			List<KeyValueVO> pNmKvList = this.assParkingService.searchParkNmKVList(provinceCd, cityCd, parkId);
			if(CollectionUtils.isNotEmpty(pNmKvList)){
				JSONArray pNmKvListJson = JSONArray.fromObject(pNmKvList.toArray());
				result.setData(pNmKvListJson);
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("获取停车场名称失败 BaseException").setThrowable(ex).info();
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("获取停车场名称失败 Exception").setThrowable(ex).info();
		}
		return result;
	}
	
	/**
	 * 根据停车场ID获取资产管理员数据
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getAssMgsByParkId.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getAssMgsByParkId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String parkId = request.getParameter("parkId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isBlank(parkId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
            return result;
		}
		try {
			
			List<KeyValueVO> pNmKvList = this.assParkingService.searchAssMgsKVList(parkId);
			if(CollectionUtils.isNotEmpty(pNmKvList)){
				JSONArray pNmKvListJson = JSONArray.fromObject(pNmKvList.toArray());
				result.setData(pNmKvListJson);
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("获取资产管理员失败 BaseException").setThrowable(ex).info();
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("获取资产管理员失败 Exception").setThrowable(ex).info();
		}
		return result;
	}
	/**
	 * 查询优车资产管理员列表
	 */
	@RequestMapping(value = "/searchManagerList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object searchManagerList(HttpServletRequest request, HttpServletResponse response) {
		List<AssParkingMgVO>  list = this.assParkingService.selectManagerList();
		String flag = request.getParameter("flag");
		if ("1".equals(flag)) {
            List<KeyValueVO> kvList = null;
            if(CollectionUtils.isNotEmpty(list)){
                kvList = new ArrayList<KeyValueVO>();
                for (AssParkingMgVO vo : list) {
                    if (vo.getManagerId() != null) {
                        KeyValueVO kv = new KeyValueVO();
                        kv.setKey(vo.getManagerId().toString());//资产管理员主键ID
                        kv.setValue(vo.getManagerRlNm()+"["+vo.getManagerNm()+"]");//资产管理员名称
                        kvList.add(kv);
                    }

                }
            }else{
                BaseLogUtils.newLogger("根据该城市代码获取停车场名称数据为空").info();
            }
            return kvList;
        }
		if(CollectionUtils.isNotEmpty(list)){
		    BaseLogUtils.newLogger("当前优车资产管理员总数").setKeys("list.size:" + list.size()).info();
		}
		return list;
	}
	
}

